package com.faiz.algorithm;

public class ValidPalindrome {

    public boolean validPalindrome(String s) {
        // 双指针
        int l = 0, r = s.length() - 1;
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                return isPalindrome(s, l++, r) || isPalindrome(s, l, r--);
            }
            l++;
            r--;
        }
        return true;
    }

    private boolean isPalindrome(String s, int l, int r) {
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                return false;
            }
            l++;
            r--;
        }
        return true;
    }

    public static void main(String[] args) {
        ValidPalindrome palindrome = new ValidPalindrome();
        String s = "cbbcc";
        boolean res = palindrome.validPalindrome(s);
        System.out.println(res);
    }
}
